# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        潘炎珍  
# Name:         test04
# Description:
# Author:       98745
# Date:         2019/4/20
#-------------------------------------------------------------------------------
from pymysql import *
import json

def dbconnect():
    db=connect('127.0.0.1','root','root','xuexi',charset='utf8')
    return db

db=dbconnect()

def select(db):
    cursor=db.cursor()
    sql='''select * from xs;'''
    cursor.execute(sql)
    results=cursor.fetchall()
    list=['id','name']
    record=[]
    for result in results:
        record.append(dict(zip(list,result)))
    print(record)
    return json.dumps(record).encode('utf-8')
    # return json.dumps(record)


js=select(db)
# print(js.decode('utf-8'))
print(js)